package ${packageName}.${controllerPackage};

import ${packageName}.${entityPackage}.${entity}Entity;
import ${packageName}.${servicePackage}.${entity}Service;
import ${packageName}.utils.JZBResult;
import ${packageName}.${requestPackage}.${entity}CreateRequest;
import ${packageName}.${requestPackage}.${entity}DeleteRequest;
import ${packageName}.${requestPackage}.${entity}ListRequest;
import ${packageName}.${requestPackage}.${entity}UpdateRequest;
import ${packageName}.${convertPackage}.${entity}ConverterConfiguration;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @Program: ${projectName}
 * @Description: ${table.comment}
 * @Author: ${author}
 * @Date: ${date}
 **/
@Slf4j
@CrossOrigin
@RestController
@Api(tags = "${table.comment}接口")
@RequestMapping(value="/${entity?uncap_first}")
public class ${entity}Controller {

    @Autowired
    private ${entity}Service ${entity?uncap_first}Service;

    /**
     * 查询${table.comment}列表
     * @param ${entity?uncap_first}ListRequest
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询${table.comment}列表")
    public JZBResult list(@RequestBody ${entity}ListRequest ${entity?uncap_first}ListRequest){
        Page<${entity}Entity> ${entity?uncap_first}EntityPage = new Page<${entity}Entity>(${entity?uncap_first}ListRequest.getPage(), ${entity?uncap_first}ListRequest.getSize());
        QueryWrapper<${entity}Entity> queryWrapper = new QueryWrapper<${entity}Entity>();
        IPage<${entity}Entity> pageInfo = ${entity?uncap_first}Service.page(${entity?uncap_first}EntityPage,queryWrapper);

        return JZBResult.ok(pageInfo);
    }

    /**
    * 增加${table.comment}
    *
    * @return
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "增加${table.comment}")
    public JZBResult add(@RequestBody @Validated ${entity}CreateRequest ${entity?uncap_first}CreateRequest){
        ${entity}Entity ${entity?uncap_first} = ${entity}ConverterConfiguration.INSTANCE.${entity}CreateRequest2${entity}Entity(${entity?uncap_first}CreateRequest);
        return JZBResult.ok(${entity?uncap_first}Service.save(${entity?uncap_first}));
    }

    /**
    * 修改${table.comment}
    *
    * @return
    */
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改${table.comment}")
    public JZBResult edit(@RequestBody @Validated ${entity}UpdateRequest ${entity?uncap_first}UpdateRequest){
        ${entity}Entity ${entity?uncap_first} = ${entity}ConverterConfiguration.INSTANCE.${entity}UpdateRequest2${entity}Entity(${entity?uncap_first}UpdateRequest);
        return JZBResult.ok(${entity?uncap_first}Service.updateById(${entity?uncap_first}));
    }

    /**
    * 删除${table.comment}
    *
    * @return
    */
    @PostMapping(value = "/del")
    @ApiOperation(value = "删除${table.comment}")
    public JZBResult del(@RequestBody @Validated ${entity}DeleteRequest ${entity?uncap_first}DeleteRequest){
        return JZBResult.ok(${entity?uncap_first}Service.removeById(${entity?uncap_first}DeleteRequest.getId()));
    }


}
